<template>
  <div class="app-container">
    <div class="formDiv">
      <el-form ref="form" :inline="true" label-width="130px">
        <el-row>
          <el-col :span="6">
            <el-form-item label="样式名称">
              <el-input v-model="params.style_name" clearable />
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="样式类型">
              <el-select v-model="params.style_type" clearable filterable>
                <el-option label="卡" value="1"></el-option>
                <el-option label="券" value="2"></el-option>
              </el-select>
            </el-form-item>
          </el-col>

          <el-col :span="8">
            <el-form-item label="添加时间">
              <el-date-picker
                v-model="time"
                type="daterange"
                value-format="yyyy-MM-dd HH:mm:ss"
                range-separator="-"
                start-placeholder="开始日期"
                end-placeholder="结束日期"
                :default-time="['00:00:00', '23:59:59']"
              />
            </el-form-item>
          </el-col>

          <el-col :span="12">
            <el-button style="margin-left:60px" type="primary" @click="searchFn">查询</el-button>
            <el-button style="margin-left:60px" type="primary" @click="addfn">添加</el-button>

            <!-- 新加 -->
            <!-- <el-button style="margin-left:60px" type="primary" @click="exfun">导出</el-button> -->
          </el-col>
        </el-row>
      </el-form>
    </div>
    <div class="listDiv">
      <!-- {{$store.state.user.permissionJson}} -->
      <el-table :data="tableData" class="tableData" style="width: 100%">
        <el-table-column
          type="index"
          label="序号"
          fixed="left"
          align="center"
          :index="table_index"
          width="50"
        ></el-table-column>
        <el-table-column label="样式名称" prop="style_name" align="center" />
        <el-table-column label="样式类型" prop="style_type" align="center">
          <template slot-scope="scope">
            <span v-if="scope.row.style_type==1">卡</span>
            <span v-if="scope.row.style_type==2">券</span>
          </template>
        </el-table-column>
        <el-table-column label="样式预览" prop="style_pic" align="center">
          <template slot-scope="scope">
            <el-popover placement="right" width="400" trigger="click">
                 <img
                style="width:100%;"
                :src="scope.row.style_pic.indexOf('http')>-1?scope.row.style_pic:url+scope.row.style_pic"
                alt
                srcset
             
              />
              <img
                style="width:100px;"
                :src="scope.row.style_pic.indexOf('http')>-1?scope.row.style_pic:url+scope.row.style_pic"
                alt
                srcset
                slot="reference"
              />
            </el-popover>
          </template>
        </el-table-column>
        <el-table-column label="创建时间" prop="created_at" align="center" >
    <template slot-scope="scope">
      {{(scope.row.created_at-0)*1000 |date(1)}}
    </template>

        </el-table-column>
        <el-table-column label="操作" prop="created_at" align="center">
          <template slot-scope="scope">
            <el-button type="text" @click="deit(scope.row)">编辑</el-button>
          </template>
        </el-table-column>
      </el-table>
      <el-pagination
        :current-page="params.page"
        :page-sizes="[10, 20, 50, 100]"
        :page-size="params.pagesize"
        layout="total, sizes, prev, pager, next, jumper"
        :total="total"
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
      />
    </div>
  </div>
</template>

<script>
import { exportfile } from "@/api/commjs/exprot";
import { list } from "@/api/CouponStore/Cardstyle";
import filter from "@/assets/filter";
export default {
  name: "",
  watch: {
    time(val) {
      this.params.created_at = val ? val[0] + " - " + val[1] : "";
    }
  },
  data() {
    return {
      total: 0,
      time: "",
      url: localStorage.getItem("imgUrlPrefix"),
      tableData: [],

      params: { page: 1, pagesize: 10 }
    };
  },
  created() {
    this.list();
  },
  methods: {
    deit(data) {
      if (data) {
        this.$router.push({ name: "addCardstyle", query: { id: data.id } });
      }
    },
    addfn() {
      this.$router.push({ name: "addCardstyle" });
    },
    searchFn() {
      this.params.page = 1;
      this.list();
    },
    async list() {
      let res = await list(this.params);
      if (res.data.code == 200) {
        this.tableData = res.data.data.data;
        this.total = res.data.data.total;
      }
    },
    table_index(index) {
      return (this.params.page - 1) * this.params.pagesize + index + 1;
    },
    handleSizeChange(val) {
      this.params.page = 1;
      this.params.pagesize = val;
      this.list();
    },
    handleCurrentChange(val) {
      this.params.page = val;
      this.list();
    }
  }
};
</script>
